﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ChangeHope.Common;

namespace YXShop.TemplateAction
{
    public partial class LabelParse
    {
        public string HistorySkim()
        {
            string mystyle = this.Label_Inserted;

            string str_TempletLayout = this.GetParamValue("YX:TempletLayout");//布局方式
            string str_ShowRows = this.GetParamValue("YX:ShowRows");//显示行数
            if (string.IsNullOrEmpty(str_ShowRows))
            {
                str_ShowRows = "1";
            }
            string str_ShowColumns = this.GetParamValue("YX:ShowColumns");//显示列数
            if (string.IsNullOrEmpty(str_ShowColumns))
            {
                str_ShowColumns = "1";
            }
            string NameCharacter = this.GetParamValue("YX:NameCharacter");//名称长度
            string WhetherOmit = this.GetParamValue("YX:WhetherOmit");//是否省略
            List<string> list = YXShop.Common.CookieUtil.GetAllHistoryCookie();
            StringBuilder shtml = new StringBuilder();
            string strcontent = string.Empty;
            YXShop.BLL.Product.ProductInfo bll = new YXShop.BLL.Product.ProductInfo();
            YXShop.Model.Product.ProductInfo model = null;
            YXShop.Common.SysParameter sp = new YXShop.Common.SysParameter();
            if (list != null && list.Count > 0)
            {
                if (!string.IsNullOrEmpty(mystyle))
                {
                    for (int i = 0; i < list.Count; i++)
                    {
                        string productId = list[i];
                        strcontent = mystyle;
                        model = bll.GetModel(Convert.ToInt32(productId));
                        if (model != null)
                        {
                            if (strcontent.IndexOf("[#Product_No]") > -1)
                            {
                                strcontent = strcontent.Replace("[#Product_No]", model.pro_NO.ToString());
                            }
                            if (strcontent.IndexOf("[#Product_Unit]") > -1)
                            {
                                strcontent = strcontent.Replace("[#Product_Unit]", model.pro_Unit.ToString());
                            }
                            int NameCharacterNu = 8;
                            if (!string.IsNullOrEmpty(NameCharacter) && ValidateHelper.IsNumber(NameCharacter))
                            {
                                NameCharacterNu = Convert.ToInt32(NameCharacter);
                            }
                            string Ellipsis = "...";
                            if (WhetherOmit == "False")
                            {
                                Ellipsis = "";
                            }
                            if (strcontent.Contains("[#Product_Name]"))
                            {
                                strcontent = strcontent.Replace("[#Product_Name]", "" + ChangeHope.Common.StringHelper.SubStringAndAppend(model.pro_Name.ToString(), NameCharacterNu, Ellipsis) + "");//商品名称

                            }
                            if (strcontent.IndexOf("[#Product_Name]") > -1)
                            {
                                strcontent = strcontent.Replace("[#Product_Name]", model.pro_Name.ToString());
                            }
                            if (strcontent.IndexOf("[#Product_ShopPrice]") > -1)
                            {
                                strcontent = strcontent.Replace("[#Product_ShopPrice]",Convert.ToDouble(model.pro_ShopPrice).ToString("f2"));
                            }
                            if (strcontent.IndexOf("[#Product_MarketPrice]") > -1)
                            {
                                strcontent = strcontent.Replace("[#Product_MarketPrice]", Convert.ToDouble(model.pro_MarketPrice).ToString("f2"));
                            }
                            if (strcontent.IndexOf("[#Product_Thumbnails]") > -1)
                            {
                                if (!string.IsNullOrEmpty(model.pro_Thumbnail.Trim()))
                                {
                                    strcontent = strcontent.Replace("[#Product_Thumbnails]", sp.DummyPaht + model.pro_Thumbnail.Trim());
                                }
                                else
                                {
                                    strcontent = strcontent.Replace("[#Product_Thumbnails]", sp.DummyPaht + "images/NaughtImages.gif");
                                }
                            }
                            if (strcontent.IndexOf("[#Product_Url]") > -1)
                            {
                                string url = YXShop.TemplateAction.Common.UrlStr("productcontent", "q_productid=" + model.pro_ID, "product/");
                                strcontent = strcontent.Replace("[#Product_Url]", url);
                            }
                            shtml.Append(strcontent);
                        }
                        if (Convert.ToInt32(str_ShowColumns) * Convert.ToInt32(str_ShowRows) == i-1)
                        {
                            break;
                        }
                    }
                }
            }
            else
            {
                shtml.Append("暂无浏览记录！");
            }
            return shtml.ToString();
        }
    }
}
